home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / PixMaps 1.1 / Example / PixMap.h < prev   
Encoding:
C/C++ Source or Header  |  1997-07-12  |  7.6 KB  |  243 lines  |  [TEXT/MPS ]

  1. /* File PixMap.h Copyright (C) 1997 by John R. Montbriand.  All Rights Reserved. */
  2.  
  3. #ifndef __PIXMAP__
  4. #define __PIXMAP__
  5.  
  6. /* File PixMap.h
  7.     PixMap manipulation routines, definitions.
  8.     Copyright (c) 1996, 1997 by John Montbriand.  All Rights Reserved.
  9.     Permission hereby granted for public use.
  10.         Distribute freely in areas where the laws of copyright apply.
  11.     USE AT YOUR OWN RISK.
  12.     DO NOT DISTRIBUTE MODIFIED COPIES.
  13.     Comments/questions/postcards* to the author at the address:
  14.       John Montbriand
  15.       P.O. Box. 1133
  16.       Saskatoon Saskatchewan Canada
  17.       S7K 3N2
  18.     or by email at:
  19.       tinyjohn@sk.sympatico.ca
  20.     *if you mail a postcard, then I will provide you with technical support
  21.     regarding questions you may have about this file.
  22.  
  23. */
  24.  
  25. #include <Types.h>
  26. #include <QuickDraw.h>
  27.  
  28. #ifdef __cplusplus
  29. extern "C" { 
  30. #endif
  31.  
  32.  
  33. /* version number for this interface (version 1) */
  34.  
  35. #define kPixMapVersion 1
  36.  
  37.  
  38. /* MakePixMap creates a new pixmap handle with the requested
  39.     dimensions.  If there is not enough memory to allocate the pixmap,
  40.     MakePixMap will return NULL.  if clut is NULL, then the default
  41.     256 colour table (clut = 8) is used.  if clut is not NULL, then a
  42.     copy of it is used in the pixmap.  The number of colours in the clut
  43.     determines the pixel depth of the created pixmap as follows:
  44.         2 colours -> 1 pit per pixel,
  45.         3 to 4 colours -> 2 bits per pixel,
  46.         5 to 16 colours -> 4 bits per pixel,
  47.         17 to 256 colours -> 8 bits per pixel. */
  48.  
  49. PixMapHandle MakePixMap(short width, short height, CTabHandle clut);
  50.  
  51.  
  52. /* Make16BitPixMap creates a new pixmap handle with the requested
  53.     dimensions.  If there is not enough memory to allocate the pixmap,
  54.     Make16BitPixMap will return NULL.  The created pixmap utilizes 16 bit
  55.     colour and allocates 16 bits per each pixel.  Make32BitPixMap is
  56.     identical however it allocates 32 bits per pixel.  */
  57.  
  58. PixMapHandle Make16BitPixMap(short width, short height);
  59. PixMapHandle Make32BitPixMap(short width, short height);
  60.  
  61.  
  62. /* MakeScreenLikePixMap creates a pixmap mirroring the attributes of the
  63.     pixmap used to draw largest area of *globalRect on the screen */ 
  64. PixMapHandle MakeScreenLikePixMap(Rect *globalRect);
  65.  
  66.  
  67. /* KillPixMap disposes of a pixmap allocated by one of the
  68.     routines herein. */
  69. void KillPixMap(PixMapHandle pix);
  70.  
  71.  
  72. /* PixMapSize returns the number of bytes occupied by the pixmap. */
  73. long PixMapSize(PixMapHandle pix);
  74.  
  75.  
  76. /* SetPixMapPixel and GetPixMapPixel are for getting or setting
  77.     individual pixel values.  */
  78.  
  79. void SetPixMapPixel(PixMapHandle pix, short h, short v, long value);
  80. long GetPixMapPixel(PixMapHandle pix, short h, short v);
  81.  
  82.  
  83. /* RotatePixRight creates a new pixmap containing the image
  84.     stored in the parameter pixmap rotated 90 degrees to the right.
  85.     The resulting pixmap is appropriately sized:  i.e. if the source
  86.     pixmap is 100 pixels wide and 200 pixels tall,  then the result
  87.     pixmap pointer will be 200 pixels wide and 100 pixels tall.  */
  88.     
  89. PixMapHandle RotatePixRight(PixMapHandle pix);
  90.  
  91.  
  92. /* RotatePixLeft creates a new pixmap containing the image stored in
  93.     the parameter bitmap pointer rotated 90 degrees to the left.  The
  94.     resulting pixmap is appropriately sized:  i.e. if the source pixmap
  95.     is 100 pixels wide and 200 pixels tall,  then the result pixmap
  96.     pointer will be 200 pixels wide and 100 pixels tall.   */
  97.     
  98. PixMapHandle RotatePixLeft(PixMapHandle pix);
  99.  
  100.  
  101. /* FlipPixVertical creates a new pixmap containing the image stored
  102.     in the parameter pixmap flipped upside down.  The resulting
  103.     pixmap will be the same size as the original image.  */
  104.     
  105. PixMapHandle FlipPixVertical(PixMapHandle pix);
  106.  
  107.  
  108. /* FlipPixHorizontal creates a new pixmap containing the image stored
  109.     in the parameter pixmap flipped horizontally. The resulting pixmap
  110.     will be the same size as the original image.  */
  111.     
  112. PixMapHandle FlipPixHorizontal(PixMapHandle pix);
  113.  
  114.  
  115. /* RotatePixMap creates a new pixmap containing the image from
  116.     the parameter pixmap rotated angle degrees about the center (cx, cy).
  117.     The resultant pixmap will have the same dimensions as the parameter
  118.     pixmap regardless of the angle specified. */
  119.     
  120. PixMapHandle RotatePixMap(PixMapHandle pix, short cx, short cy, float angle);
  121.  
  122.  
  123. /* DuplicatePixMap creates a copy of the pixmap parameter. */
  124.  
  125. PixMapHandle DuplicatePixMap(PixMapHandle pix);
  126.  
  127.  
  128. /* PICTToBitMap creates a new pixmap the using the size information
  129.     provided in the QuickDraw picture pointer parameter and draws
  130.     the picture in the pixmap before returning the pixmap. */
  131.     
  132. PixMapHandle PICTToPixMap(PicHandle pic, CTabHandle clut);
  133. PixMapHandle PICTTo16BitPixMap(PicHandle pic);
  134. PixMapHandle PICTTo32BitPixMap(PicHandle pic);
  135.  
  136.  
  137. /* PixMapToPICT returns a QuickDraw picture that will draw the
  138.     image stored in the pixmap.  PixMapToPICT is the inverse
  139.     of PICTToPixMap. */
  140.     
  141. PicHandle PixMapToPICT(PixMapHandle pix);
  142.  
  143.  
  144. /* PixMapToCompressedPICT returns a QuickDraw picture that will draw the
  145.     image stored in the pixmap.  PixMapToCompressedPICT is the inverse
  146.     of PICTToPixMap. */
  147.     
  148. PicHandle PixMapToCompressedPICT(PixMapHandle pix);
  149.  
  150.  
  151.  
  152. /* ROUTINES FOR DRAWING TO... */
  153.  
  154. /* PixMapPort data structure managed by the routines NewBMP and
  155.     DisposeBMP.  You should never have to access the fields of this
  156.     record directly as it's all taken care of by NewBMP and DisposeBMP. */
  157.  
  158. typedef struct {
  159.     CGrafPort pport;        /* the grafport record for drawing into the pixmap */
  160.     GDHandle pdevice;        /* gdevice for drawing into the pixmap */
  161.     GDHandle saved_device;    /* saved gdevice */
  162.     GrafPtr saved_port;        /* saved grafport for later restoration */
  163.     PixMapHandle pix;        /* the pixmap */
  164. } PixMapPort;
  165.  
  166.  
  167. /* NewBMP is called by the WithBitMap macro and you should never have to
  168.     call it directly yourself.  What it does is it locks the pixmap, saves the
  169.     original grafport, and creates a new grafport suitable for drawing into
  170.     the pixmap.  NewBMP should be followed by a call to DisposeBMP which
  171.     will restore the original grafport, unlock the pixmap, and dispose of the
  172.     new grafport. */
  173.     
  174. PixMapPort* NewPxMP(PixMapHandle pix);
  175.  
  176.  
  177.  
  178. /* DisposePxMP unlocks the pixmap pointer passed to NewPxMP, deallocates
  179.     the grafport allocated for it, and restores the original grafport.
  180.     the macro WithBitMap calls this routine automatically and you will
  181.     not normally have to call it directly. */
  182.     
  183. void DisposePxMP(PixMapPort* px);
  184.  
  185.  
  186.  
  187. /* WithPixMap is a macro facility that sets up the drawing environment
  188.     such that any drawing commands in the statement following the
  189.     macro instantiation will draw into the pixmap handle provided as
  190.     the first parameter.  The parameters are declared as follows:
  191.         PixMapHandle pix;
  192.         PixMapPort* pxmp; */
  193.     
  194. #define WithPixMap(pix, pxmp) \
  195.     for (pxmp = NewPxMP(pix); \
  196.         pxmp != NULL; \
  197.         DisposePxMP(pxmp), pxmp = NULL)
  198.  
  199.  
  200.  
  201.  
  202. /* ROUTINES FOR DRAWING FROM... */
  203.  
  204. /* PlotPixMap provides a simple interface for drawing a pixmap in
  205.     the current grafport.  The pixmap is drawn with the top left corner
  206.     aligned with the point (h,v) using the indicated transfer mode. */
  207.  
  208. void PlotPixMap(PixMapHandle pix, short h, short v, short mode);
  209.  
  210.  
  211. /* PixMapCopy copies bits from the pixmap to the current port
  212.     from the src rectangle to the destination using the indicated
  213.     copy mode. */
  214.  
  215. void PixMapCopy(PixMapHandle pix, Rect *src, Rect *dst, short mode);
  216.  
  217.  
  218. /* PixMap2PixPat converts a pixmap to a pixel pattern resource.  The
  219.     pixmap's dimensions should be some power of two
  220.     (i.e. 8, 16, 32, 64, or 128). */
  221.  
  222. PixPatHandle PixMap2PixPat(PixMapHandle pix, Pattern *the_pattern);
  223.  
  224.  
  225. /* CalcPixMapColours calculates a colour table for the colours
  226.     used in the pixmap.  For indexed images, CalcPixMapColours returns
  227.     a copy of the pixmap's colour table, otherwise, for direct
  228.     images, it calls GetPixMapInfo. */
  229.  
  230. CTabHandle CalcPixMapColours(PixMapHandle pix);
  231.  
  232.  
  233. #ifdef __cplusplus
  234. };
  235. #endif
  236.  
  237. #endif
  238.  
  239. /* end of File PixMap.h */
  240.  
  241.  
  242.  
  243.